/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.app.model;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

/**
 *
 * @author Thuan
 */
@Entity
@Table(name = "SchoolYear")
@NamedQueries({
    @NamedQuery(name = "SchoolYear.findAll", query = "SELECT s FROM SchoolYear s"),
    @NamedQuery(name = "SchoolYear.findBySchoolYearId", query = "SELECT s FROM SchoolYear s WHERE s.schoolYearId = :schoolYearId"),
    @NamedQuery(name = "SchoolYear.findByCodeToGen", query = "SELECT s FROM SchoolYear s WHERE s.codeToGen = :codeToGen"),
    @NamedQuery(name = "SchoolYear.findByName", query = "SELECT s FROM SchoolYear s WHERE s.name = :name"),
    @NamedQuery(name = "SchoolYear.findByOrderNo", query = "SELECT s FROM SchoolYear s WHERE s.orderNo = :orderNo")})
public class SchoolYear implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "schoolYearId")
    private Integer schoolYearId;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 5)
    @Column(name = "codeToGen")
    private String codeToGen;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 50)
    @Column(name = "name")
    private String name;
    @Column(name = "orderNo")
    private Integer orderNo;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "schoolYearId")
    private Collection<Semester> semesterCollection;

    public SchoolYear() {
    }

    public SchoolYear(Integer schoolYearId) {
        this.schoolYearId = schoolYearId;
    }

    public SchoolYear(Integer schoolYearId, String codeToGen, String name) {
        this.schoolYearId = schoolYearId;
        this.codeToGen = codeToGen;
        this.name = name;
    }

    public Integer getSchoolYearId() {
        return schoolYearId;
    }

    public void setSchoolYearId(Integer schoolYearId) {
        this.schoolYearId = schoolYearId;
    }

    public String getCodeToGen() {
        return codeToGen;
    }

    public void setCodeToGen(String codeToGen) {
        this.codeToGen = codeToGen;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getOrderNo() {
        return orderNo;
    }

    public void setOrderNo(Integer orderNo) {
        this.orderNo = orderNo;
    }

    public Collection<Semester> getSemesterCollection() {
        return semesterCollection;
    }

    public void setSemesterCollection(Collection<Semester> semesterCollection) {
        this.semesterCollection = semesterCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (schoolYearId != null ? schoolYearId.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof SchoolYear)) {
            return false;
        }
        SchoolYear other = (SchoolYear) object;
        if ((this.schoolYearId == null && other.schoolYearId != null) || (this.schoolYearId != null && !this.schoolYearId.equals(other.schoolYearId))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        //return "com.app.model.SchoolYear[ schoolYearId=" + schoolYearId + " ]";
        return name;
    }

}
